PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Nested Tell Statements

You can nest a Tell statement inside another Tell statement as long as every statement in a Tell block can be handled by the target application specified in the Tell statement (or by AppleScript). For example, the following script will compile and run successfully:

tell application "Finder"
    tell document 1 of application "AppleWorks"
        get style of text body -- handled by AppleWorks
    end tell
    set fileName to name of first file ¬
        of startup disk -- handled by Finder
    count characters in fileName -- handled by AppleScript
end tell

This example works because an AppleWorks document can get the style of its text body, the Finder can get the name of the first file on the startup disk, and AppleScript can count the characters in a string. Notice what happens, however, when we move one statement in the previous script:

tell application "Finder"
    tell document 1 of application "AppleWorks"
        get style of text body -- handled by AppleWorks
        set fileName to name of first file of startup disk -- ERROR!
            -- AppleWorks doesn't know how to handle this statement!
    end tell
    count characters in fileName -- handled by AppleScript
end tell

Because the script attempts to get the name of a file from within a Tell statement that specifies AppleWorks, running this script generates an error.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)